#ifndef __CAN_H
#define __CAN_H

#if defined(__cplusplus)
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>

#include <linux/can.h>
#include <linux/can/raw.h>
#if defined(__cplusplus)
}
#endif


class can
{
public:
                                can() {
                                }
                               ~can() {
                                }
                            int opendev(const char *name);
                     inline int closedev() {
                                    return close(msockfd);
                                }
                     inline int sendframe(struct can_frame *sframe) {
                                    return write(msockfd, sframe, sizeof(struct can_frame));
                                }
                     inline int recvframe(struct can_frame *cframe) {
                                    return read(msockfd, cframe, sizeof(struct can_frame));
                                }
                     inline int set_nonblock() {
                                    return fcntl(msockfd, F_SETFL, O_NONBLOCK);
                                }
private:
                            int msockfd;
                   struct ifreq mifreq;
            struct sockaddr_can maddr;
};

#endif // CAN_H
